x=int(input())
f=str(x)
max=0
if int(x)>999 and int(x)<10000:
    for i in range(len(f)):
        for g in range(i+1,len(f)+1):
            h=int(f[i:g])
            if h>1:
                q=True
                if h<=3:
                    q=True
                elif h%2==0 or h%3==0:
                    q=False
                else:
                    j=5
                    while j*j<=h:
                        if h%j==0 or h%(j+2)==0:
                            q=False
                            break
                        j+=6
                if q and h>max:
                    max=h
res=0
if max==0:
    print(res)
else:
    print(max)
